﻿@model MAPDavy.WebMVC3.Models.UserDTO

@{
    ViewBag.Title = "AgignarRol";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section JavaScript{
<script type="text/javascript">
    $(document).ready(function () {
        $("#roles").css("height", "300px");
        $("#roles").css("width", "200px");
        $("#userRoles").css("height", "300px");
        $("#userRoles").css("width", "200px");

        $("#btnAdd").button({
            icons: {
                secondary: "ui-icon-seek-next"
            }
        })

        $("#btnRemove").button({
            icons: {
                primary: "ui-icon-seek-prev"
            }
        })

        $("#btnAdd").click(function () {

            var _userName = $("#UserName").val();

            $("#roles option:selected").each(function () {

                var _rol = $(this).val();
                    $.post(
                        '@Url.Action("AddRol", "Account")',
                        { userName: _userName, rol: _rol},
                        function (ok) {
                            if (ok) {
                                $("#userRoles").append(
                                    $('<option>').text(_rol).val(_rol)
                                ).find('option:last').hide().fadeIn("slow");

                                $('#roles > option[value="' + _rol + '"]').remove().fadeIn("slow");
                        }
                        else {
                            jAlert("No se ha podito agregar el Rol:<br/><b>" + _rol + "</b>", "Advertencia");
                        }
                    },
                    "json"
                    );                
            });
        });

       $("#btnRemove").click(function () {

        var _userName = $("#UserName").val();

            $("#userRoles option:selected").each(function () {

                    var _rol = $(this).val();
                    $.post(
                        '@Url.Action("RemoveRol", "Account")',
                        { userName: _userName, rol: _rol },
                        function (ok) {
                            if (ok) {
                                $("#roles").append(
                                    $('<option>').text(_rol).val(_rol)
                                ).find('option:last').hide().fadeIn("slow");

                                $('#userRoles > option[value="' + _rol + '"]').remove().fadeIn("slow");
                            }
                            else {
                                jAlert("No se ha podito Quitar el Rol:<br/><b>" + _rol + "</b>", "Advertencia");
                            }
                        },
                    "json"
                    );
                });
       });
    });
</script>
}  
<div class="cpanel ui-widget ui-widget-content ui-corner-all">
    <table class="toolbar">
        <tr>
            <td valign="middle" >
                <img src="@Url.Content("~/Content/images/asingRol.png")" title="Usuarios" alt="Usuarios" />
            </td>
            <td class="tdHeader">
                <span class="header">
                    Agignar Rol .::. User Name: @Html.DisplayFor(model => model.UserName)
                </span>
                @Html.HiddenFor(model => model.UserName)
            </td>
            <td><center>
                <a href="@Url.Action("Index", "Account")">
                    <img src="@Url.Content("~/Content/images/back.png")" title="Candelar" alt="Cancelar" />
                    <br /><span class="label">Cancelar</span>
                </a></center>
            </td>
        </tr>
    </table>
</div>            
 <div class = "titleView ui-widget ui-widget-content ui-corner-all">
    <table border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td>
                <center><b>Roles Disponibles</b></center>
                @Html.ListBox("roles")
            </td>
            <td valign="middle">
                <center>
                    <button id="btnAdd">Agregar</button><br /><br />
                    <button id="btnRemove">Quitar</button>
                </center>                
            </td>
            <td>
                <center><b>Roles Asignados</b></center>
                @Html.ListBox("userRoles")
            </td>
        </tr>
    </table>     
</div>
